Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

171
Vistas
I am facing an error of "TypeError: Cannot read properties of undefined (reading 'push')"

I have been facing this issue while using history.push('/pathname') in app.js component. my requirement is that I have to use this history.push inside an onclick handler defined in app.js component which is then sent to button component in via props. I am not able to figure out the solution of this error. (The button component is AppointmentNextBtn). Please guide me.

import { useHistory } from "react-router-dom";
function App(){
  const history = useHistory();
  const onClickNextDateHandler = () => {
history.push("/selectlocation/appointment/selectdate");
console.log("date button runs");
setNextBtnState("time");

};

return(
<Route exact path="/selectlocation/appointment">
        <Toappointmentcontainer
          postAppointmentRequest={postRequestAppointment}
        />
        <div className="btnwidget">
          <AppointmentNextBtn
            onClickDateHandler={onClickNextDateHandler}
            displayState={nextBtnState}
            text="Next"
            button="button"
          />
        </div>
      </Route>

)

}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You cannot use history in the same file you declare your route. History objects will always be unavailable in this case. Best way is to do directly it in appointmentNextBtn.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda